import React, { Component } from 'react';
import { AppRegistry, Navigator, View,StyleSheet, BackAndroid,StatusBar} from 'react-native';
import loginView from './jscore/modules/loginView';
import RepairList from './jscore/modules/RepairList';
class HomeView extends Component{
  constructor(props){
    super(props)
    this.handleBack = this._handleBack.bind(this)
  }

  /**
   * 组件挂在的时候会调用此方法
   */
  componentDidMount() {
    BackAndroid.addEventListener("hardwareBackPress",this.handleBack);
  }

  /**
   * 组件移除的时候调用此方法
   */
  componentDidUnMount() {
    BackAndroid.addEventListener("hardwareBackPress",this.handleBack);
  }

  //返回处理函数
  _handleBack(){
    var navigator = this.Navigator;
    if(navigator && navigator.getCurrentRoutes().length>1){
      navigator.pop();
      return true;
    }else{
      return false;
    }
  }
  render(){
    return(
        <View style={styles.container}>
          <StatusBar
              backgroundColor="#1b91ff"
              barStyle="light-content"
          />
          <Navigator
              ref={component => this.navigator = component}
              initialRoute={{
                component: loginView //文件名
              }}
              renderScene={(route, navigator) => { // 用来渲染navigator栈顶的route里的component页面
                return <route.component navigator={navigator} {...route} {...route.passProps}/>// {...route.passProps}即就是把passProps里的键值对全部以给属性赋值的方式展开 如：test={10}
              }}/>
        </View>
    );
  }



}


var styles = StyleSheet.create({
  container:{
    flex:1
  },
});

AppRegistry.registerComponent('ReactDemo', () => HomeView);
